<template>
  <div class="page_space btn_space">
    <p class="title_1">基本信息</p>
    <input-card>
      <input-item :content="form.sampleBarcode" title="样品自编号" />
      <input-item :content="form.sampleName" title="样品名称" />
      <input-item :content="form.reportCode" title="关联采样单编号" />
      <input-item :content="form.name" title="快检类型" />
    </input-card>

    <p class="title_1">基本信息</p>
    <input-card>
      <input-item
        v-model="form.employeeName"
        :content="form.employeeName"
        title="检测人员"
        tip="请选择检测人员"
        type="select"
        @select="goto('/sampling-test/select-person')"
      />
      <input-item-time
        v-model="form.reportDate"
        title="检测日期"
        tip="请输入检测日期"
      />
    </input-card>

    <p class="title_1">
      <span>检测信息</span>
      <span v-debounce class="right" @click="addInfo">添加</span>
    </p>
    <input-card
      v-for="(item, index) in form.detailInfo"
      :key="index"
      class="mb-15"
    >
      <input-item
        :content="item.sampleProjectName"
        title="检测项目"
        tip="请选择检测项目"
        type="select"
        @select="goto('/sampling-test/select-project?index=' + index)"
      />
      <input-item :content="item.sampleMethod" title="检测方法" />
      <input-item :content="item.standardValue" title="检测低限" />
      <item-input v-model="item.value" title="检测值" tip="请输入检测值" />
      <input-item
        :content="item.inspectionUnit"
        title="检测值计量单位"
        tip="请选择检测项目"
      />
      <input-item
        :content="item.fieldName"
        title="快检产品信息"
        tip="请选择检测项目"
        type="select"
        @select="goto('/sampling-test/select-product?index=' + index)"
      />
      <input-item
        :content="item.fieldName"
        title="设备信息"
        tip="请选择设备信息"
        type="select"
        @select="goto('/sampling-test/select-equipment?index=' + index)"
      />
      <input-item
        :content="item.result"
        title="结果判定"
        tip="请选择检测项目"
      />
      <div class="btn_delete" @click="">删除</div>
    </input-card>

    <p class="title_1">检测结果</p>
    <input-card>
      <input-item-radio
        v-model="radioValue"
        :option="[
          { label: '合格', value: 'true' },
          { label: '不合格', value: 'false' }
        ]"
        title="最终结果判定"
      />
      <!-- {{ radioValue }} -->
      <input-item-sign
        title="检测人签名"
        value="2310161534054350000"
        @click="$router.push('/sign')"
      />
    </input-card>

    <div class="btn_wrap">
      <button class="btn middle default" @click="$router.go(-1)">返回</button>
      <button class="btn middle" @click="">提交</button>
    </div>

    <van-popup v-model="show" position="bottom" :round="true"> </van-popup>
  </div>
</template>

<script>
import inputCard from '@/components/input-card/card'
import inputItem from '@/components/input-card/item'
import inputItemRadio from '@/components/input-card/item-radio'
import inputItemSign from '@/components/input-card/item-sign'
import inputItemTime from '@/components/input-card/item-time'
import itemInput from '@/components/input-card/item-input'
import { saveDetection, getDetails } from '@/api/detection'
import { ParseDate } from '@/utils'
import { store, mutations } from '@/observable'

export default {
  name: 'immediateDetection',
  components: {
    inputCard,
    inputItem,
    inputItemRadio,
    inputItemSign,
    inputItemTime,
    itemInput
  },
  data() {
    return {
      show: false,
      active: 0,
      // 时间picker
      currentDate: new Date(),
      radioValue: 0,
      qualification: {},
      form: {
        reportDate: '',
        employeeInfoId: '', // 检测人员ID
        employeeName: '', // 检测人员
        relationBillId: '2310181623467990000',
        sampleBarcode: '25342', // 项目自编号
        sampleName: '西瓜',
        reportCode: 'CY20231018013',
        detailInfoType: 'firstCheck',
        result: 'qualified',
        dataSource: 'fastCheckProduct',
        businessFileDTOJson: [{ fileId: '2310181624213240000' }],
        detailInfo: [
          {
            /* 产品 START */
            dataSource: 'fastCheckProduct', // 固定
            businessVarietyInfoId: '',
            businessVarietyName:
              '444/PC202310180001/12mg/L、测试快检产品/PC202310160001/21mg/L', // 快检产品信息
            fastCheckStorageDetailId: '',
            ioStockInfoDTOList: [
              {
                placeId: '2310181553317800000',
                placeName: '茂名市茂南区',
                stockNum: 12, // 出库数量
                inventoryBatch: 'PC202310180001',
                businessVarietyId: '2310161146251840000',
                businessVarietyName: '',
                batch: 'PC11221',
                inStockDate: '2023-10-18'
              },
              {
                placeId: '2310161046503310000',
                placeName: '茂名市',
                stockNum: 21, // 出库数量
                inventoryBatch: 'PC202310160001',
                businessVarietyId: '2310161046190950000',
                businessVarietyName: '',
                batch: 'PC111',
                inStockDate: '2023-10-01'
              }
            ],
            /* 产品 END */
            /* 检测项目 START */
            sampleProjectId: '2307121604154590000',
            sampleProjectName: '呋喃西林代谢物', // 检测项目
            sampleMethod: '胶体金法', // 检测方法
            method: 'GLUE_GOLD_PROCESS',
            standardValue: '0.5', // 检测低限
            inspectionUnit: '',
            value: '',
            /* 检测项目 END */

            /* 设备信息 START */
            equipmentId: '2310161528589990000',
            equipmentName: '432532432',
            /* 设备信息 END */
            num: '',

            singleResult: 'positive', // 结果判断 阴性 negative 阳性 positive
            type: 'firstCheck' // 待检测：firstCheck ； 初检不合格：secondCheck
          }
        ]
      }
    }
  },
  beforeRouteLeave(to, from, next) {
    next()
  },
  activated() {
    // 获取-检测人员
    if (JSON.stringify(store.inspectorInfo) !== '{}') {
      let { employeeInfoId, employeeName } = store.inspectorInfo
      this.form.employeeName = employeeName
      this.form.employeeInfoId = employeeInfoId
    }
    // 获取-检测项目
    if (JSON.stringify(store.inspectorProjectInfo) !== '{}') {
      let info = store.inspectorProjectInfo
      let INDEX = info.INDEX
      this.form.detailInfo[INDEX].sampleProjectId = info.sampleProjectId
      this.form.detailInfo[INDEX].sampleProjectName = info.sampleProjectName
      this.form.detailInfo[INDEX].sampleMethod = info.sampleMethod
      this.form.detailInfo[INDEX].method = info.method
      this.form.detailInfo[INDEX].standardValue = info.standardValue
      this.form.detailInfo[INDEX].inspectionUnit = info.inspectionUnit
      this.form.detailInfo[INDEX].value = info.value
    }
    // 获取-检测设备
    if (JSON.stringify(store.inspectorEquipmentInfo) !== '{}') {
      let { equipmentId, equipmentName, INDEX } = store.inspectorEquipmentInfo
      this.form.detailInfo[INDEX].equipmentId = equipmentId
      this.form.detailInfo[INDEX].equipmentName = equipmentName
    }
  },
  methods: {
    // 获取详情
    async getDetails() {
      let id = this.$router.query.id
      const { code, data } = await getDetails(id)
    },
    addInfo() {
      let info = {
        dataSource: 'fastCheckProduct',
        businessVarietyInfoId: '',
        businessVarietyName:
          '444/PC202310180001/12mg/L、测试快检产品/PC202310160001/21mg/L', // 快检产品信息
        fastCheckStorageDetailId: '',
        sampleProjectId: '2307121604154590000',
        sampleProjectName: '呋喃西林代谢物', // 检测项目
        sampleMethod: '胶体金法', // 检测方法
        method: 'GLUE_GOLD_PROCESS',
        standardValue: '0.5', // 检测低限
        inspectionUnit: '',
        value: '',
        equipmentId: '2310161528589990000',
        equipmentName: '432532432',
        singleResult: 'positive',
        num: '',
        ioStockInfoDTOList: [
          {
            placeId: '2310181553317800000',
            placeName: '茂名市茂南区',
            stockNum: 12,
            inventoryBatch: 'PC202310180001',
            businessVarietyId: '2310161146251840000',
            businessVarietyName: '',
            batch: 'PC11221',
            inStockDate: '2023-10-18'
          },
          {
            placeId: '2310161046503310000',
            placeName: '茂名市',
            stockNum: 21,
            inventoryBatch: 'PC202310160001',
            businessVarietyId: '2310161046190950000',
            businessVarietyName: '',
            batch: 'PC111',
            inStockDate: '2023-10-01'
          }
        ],
        type: 'firstCheck'
      }
      this.form.detailInfo.push(info)
    }
  }
}
</script>

<style scoped lang="scss">
.btn_delete {
  text-align: center;
  color: rgba(255, 4, 4, 1);
  font-size: 14px;
}
</style>
